package com.pls.handlers;

import java.util.ArrayList;

import com.plsContracts.dataContracts.DeleteEmployeeSeatRequest;
import com.plsContracts.dataContracts.DeleteEmployeeSeatResponse;
import com.plsDTO.validation.ValidationError;
import com.plsData.data.EmployeeData;

public class DeleteEmployeeSeatHandler extends
		RequestHandler<DeleteEmployeeSeatResponse, DeleteEmployeeSeatRequest> {

	public DeleteEmployeeSeatHandler(Class<DeleteEmployeeSeatResponse> tResponse) {
		super(tResponse);
		// TODO Auto-generated constructor stub
	}

	protected ArrayList<ValidationError> validate(DeleteEmployeeSeatRequest request) {
		ArrayList<ValidationError> errors = new ArrayList<ValidationError>();
		ValidationError valError;
		if (request == null) {
			valError = new ValidationError();
			valError.setMessage("Request is null.");
			valError.setName("NullRequest");
			errors.add(valError);
			return errors;
		}
		if (request.getEmployeeId() == 0) {
			valError = new ValidationError();
			valError.setMessage("Employee Id cannot be null.");
			valError.setName("InvalidInput");
			errors.add(valError);
		}
		if (request.getSeatCode() == null) {
			valError = new ValidationError();
			valError.setMessage("Seat code cannot be null.");
			valError.setName("InvalidInput");
			errors.add(valError);
		}

		return errors;
	}
	
	public DeleteEmployeeSeatResponse process(DeleteEmployeeSeatRequest request){
		
		DeleteEmployeeSeatResponse response = new DeleteEmployeeSeatResponse();
		//call data layer
		
		EmployeeData empData = new EmployeeData();
		boolean isSuccesful = empData.deleteEmployeeSeat(request.getEmployeeId(), request.getSeatCode());
		response.setSuccessful(isSuccesful);
		
		return response;
	}
	
}
